home *** CD-ROM | disk | FTP | other *** search
- /*************************************************
- * *
- * E! for Windows *
- * (c) - Patrick Philippot - 1992,1993 *
- * *
- * MulHelp2 Extension DLL - version 2.1 *
- * *
- * Supporting multiple Help Files from E!. *
- * *
- *************************************************/
-
- /*
- MULHELP2 is a much more sophisticated version of MULHELP. There are
- many situations where you have to refer to multiple help files. For
- example, when writing Visual C++ source code with E!, you may want
- to refer to the Windows 3.1 SDK, the MFC 2.5 and the C/C++ language
- help files. It would be nice to load one of this file at will when
- the cursor is located on a keyword.
-
- With MULHELP2 you can.
-
- With MULHELP, each alternate help file was assigned a different key.
- MULHELP2 has another approach. When you hit SHIFT+F1 (or the key that
- you have assigned to the AlternateHelp function), a listbox is
- displayed, showing the list of all the alternate help files that you
- have specified in EW.INI. Select one of these and WinHelp will be
- called with the selected help file and the current keyword as
- parameters.
-
- But there's more to MULHELP2, however. This DLL installs a hook on the
- JumpToDefinition function. When you ask E! to jump to a function definition
- and when E! can't find this definition in the TAG file, MULHELP2 takes
- control and asks the user whether he wants the keyword to be passed to
- one of the registered help files.
-
-
- Installing MULHELP2
- *******************
-
- The first thing you have to do is to create a new section in EW.INI:
- [extended help]. Then, you will list in that section the help files
- you want to use, as follows (this is an example):
-
- HelpName1=win31wh.hlp
- HelpName2=mfc.hlp
- HelpName3=mscxx.hlp
-
- You must then add a description for each of these files:
-
- HelpDesc1=Windows SDK Help File
- HelpDesc2=MFC 2.5 Help File
- HelpDesc3=Microsoft C/C++ Language Help File
-
- and so on...
-
- You should then load MULHELP2 from the User menu (you can also
- install MULHELP2 as an autoloaded EWD). MULHELP2.EWD must reside in
- your USER directory.
-
- WARNING!!
-
- If you had previously installed MULHELP.EWD, you should unload it,
- remove it from your autoload list if necessary and remove any
- assignment to the SHIFT+F1 key (or to the key to which you have
- assigned the AlternateHelp function).
-
- Once MULHELP2 is loaded, when you hit SHIFT+F1, the list of help
- file descriptors will be displayed and you'll just have to select
- one to get help about the current keyword if it is relevant for the
- selected help file.
-
-
- Enjoy!
-
- Patrick Philippot
- 01-12-95
- */
-
- #include <windows.h>
- #include "ewapi2.h"
- #include <stdlib.h>
- #include <string.h>
-
- char HelpEntry[] = "HelpName";
- char HelpDesc[] = "HelpDesc";
- char HelpSection[] = "Extended Help";
- char Profile[] = "ew.ini";
-
- #define id_ListBox 100
-
- char EntryValue[81];
- char HelpCurEntry[81];
- HWND ListBoxHandle, OkBtHandle;
- HANDLE hInst;
-
-
- BOOL CALLBACK ChoiceDlg(HWND hwndDlg, UINT Message, WPARAM wParam, LPARAM lParam)
- // This is the dialog procedure managing the Help File Description List
- {
- int Index ;
- char IndexStr[4];
-
- switch (Message)
- {
- case WM_INITDIALOG:
- // Get handle of Listbox
- ListBoxHandle = GetDlgItem(hwndDlg, id_ListBox);
- OkBtHandle = GetDlgItem(hwndDlg, IDOK);
- EnableWindow(OkBtHandle, FALSE);
- SetFocus(ListBoxHandle);
- // Fill listbox with name of registered help files
- Index = 1;
- _itoa(Index, IndexStr, 10);
- _fstrcat(_fstrcpy(HelpCurEntry, HelpDesc), IndexStr);
- // Iterate through list of help file descriptors
- while (GetPrivateProfileString(HelpSection,
- HelpCurEntry,
- "",
- EntryValue,
- sizeof(EntryValue),
- Profile) != 0)
- {
- // Add descriptor to Listbox
- SendMessage(ListBoxHandle, LB_ADDSTRING, 0, (LPARAM) EntryValue);
- Index++;
- _itoa(Index, IndexStr, 10);
- _fstrcat(_fstrcpy(HelpCurEntry, HelpDesc), IndexStr);
- }
- return TRUE;
- case WM_COMMAND:
- switch (wParam)
- {
- case id_ListBox:
- if (HIWORD(lParam) != LBN_DBLCLK)
- // A double_click is processed as the IDOK command
- {
- if (HIWORD(lParam) == LBN_SELCHANGE)
- {
- EnableWindow(OkBtHandle, TRUE);
- return TRUE;
- }
- else
- return FALSE;
- }
- case IDOK:
- Index = SendMessage(ListBoxHandle, LB_GETCURSEL, 0, 0);
- if (Index != LB_ERR)
- // A Help File Descriptor is currently selected
- {
- _itoa(Index + 1, IndexStr, 10);
- _fstrcat(_fstrcpy(HelpCurEntry, HelpEntry), IndexStr);
- // Get the corresponding help filename
- if (GetPrivateProfileString(HelpSection,
- HelpCurEntry,
- "",
- EntryValue,
- sizeof(EntryValue),
- Profile) != 0)
- // It is important to close the dialog box before calling an E! API
- // function. Otherwise, E! is unable to know which Edit Window is active
- {
- EndDialog(hwndDlg, IDOK);
- WritePrivateProfileString("system",
- "alternatehelp",
- EntryValue,
- Profile);
- EWAlternateHelp(EWGetCaretPosX(), EWGetCaretPosY());
- return TRUE;
- }
- else
- // No Help Filename could be found for the Descriptor with this index
- {
- MessageBeep(0);
- EWMessageBox(GetFocus(),
- "Can't find related Help File.",
- "Error!",
- MB_OK | MB_ICONEXCLAMATION);
- }
- }
- else
- {
- MessageBeep(0);
- EWMessageBox(GetFocus(),
- "No Help File Selected.",
- "Error!",
- MB_OK | MB_ICONEXCLAMATION);
- };
- case IDCANCEL:
- EndDialog(hwndDlg, IDCANCEL);
- return TRUE;
- }
- default:
- return FALSE;
- }
- }
-
- int FAR PASCAL _export FuncEntryHook(unsigned int command)
- // Install a hook for the AlternateHelp function.
- {
- static BOOL bInUse = FALSE;
- DLGPROC ChoiceProc;
-
- if ((!bInUse) && (command == ew_AlternateHelp))
- {
- bInUse = TRUE;
- ChoiceProc = (DLGPROC) MakeProcInstance(ChoiceDlg, hInst);
- DialogBox(hInst, "HelpList", GetFocus(), ChoiceProc);
- FreeProcInstance((FARPROC) ChoiceProc);
- bInUse = FALSE;
- return 1;
- }
- else
- return 0;
- }
-
- int FAR PASCAL _export FuncExitHook(unsigned int command, int FAR* pRetcode)
- // Check whether the JumpToDef function succeeded.
- // If not, ask the user whether the keyword should be passed to a help file
- {
- if ((command == ew_MCJumpToDef) && (*pRetcode != 0))
- if (EWMessageBox(GetFocus(),
- "No Definition found for this function. Pass Keyword to a Help File?",
- "Error",
- MB_YESNO) == IDYES)
- *pRetcode = EWAlternateHelp(EWGetCaretPosX(), EWGetCaretPosY());
- // Although the current version of the EW API doesn't check the return code
- // from the FuncExitHook functions, it is good practice to set this value
- // to 0.
- return 0;
- }
-
- int FAR PASCAL _export _WEP(int nExitType)
- {
- // Uninstall Hook before exiting}
- EWRemoveHook(EWHook_FunctionEntry, FuncEntryHook);
- EWRemoveHook(EWHook_FunctionExit, FuncExitHook);
-
- return 1;
- }
-
- int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
- LPSTR lpszCmdLine)
- {
- hInst = hInstance;
-
- if (wHeapSize > 0)
- UnlockData (0) ;
-
- // Install Function Entry Hook on the AlternateHelp function
- EWSetHook(EWHook_FunctionEntry, FuncEntryHook);
- EWSetHook(EWHook_FunctionExit, FuncExitHook);
-
- return 1;
- }
-
-